package cn.fl.ass.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.user.facade.system.condition.SysUsrFunAuthRQueryCondition;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.ass.service.IAssDealCarCostService;
import cn.fl.ass.service.IAssDealCarService;
import cn.fl.ass.service.IAssDealRecAmtService;
import cn.fl.ass.service.IAssDealSellService;
import cn.fl.ass.vo.AssDealCarCostVO;
import cn.fl.ass.vo.AssDealCarVO;
import cn.fl.ass.vo.AssDealRecAmtVO;
import cn.fl.ass.vo.AssDealSellVO;
import cn.fl.capital.service.ICapFundService;
import cn.fl.capital.vo.CapFundVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.finance.constant.FinLoanConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.insurance.constant.InsuranceConstant;
import cn.fl.project.constant.PrjPrdPaySchMConstant;
import cn.fl.project.dto.PrjPrdPaySchMDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdPaySchMService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjPrdPaySchMVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysEmpBankAccService;
import cn.fl.system.vo.SysEmpBankAccVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.ass.facade.constant.AssDealSellConstant;
import fl.ass.facade.constant.InterfaceConstants;
import fl.ass.facade.dto.AssDealSellDTO;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @Description:    优车处置controller
* @Author:         liurong
* @CreateDate:     2020/5/19 9:52
* @Version:        1.0
*/
@Controller
@RequestMapping("/ass/ucardeal")
public class AssUCarDealController extends BaseController {

	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	@Autowired
	private IAssDealSellService assDealSellService;

	@Autowired
	private IAssDealCarService assDealCarService;

	@Autowired
	private IAssDealRecAmtService assDealRecAmtService;

	@Autowired
	private IAssDealCarCostService assDealCarCostService;

	@Autowired
	private ISysEmpBankAccService sysEmpBankAccService;

	@Autowired
	private ICapFundService capFundService;

	@Autowired
	private IPrjPrdPaySchMService prjPrdPaySchMService;

	@Autowired
	private IPrjBscInfoService prjBscInfoService;

	@Autowired
	private ICstBscInfoService cstBscInfoService;

	/**
	 * 跳转优车处置流程附加页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toUCarDealFlowPage.do", method = { RequestMethod.GET})
	public ModelAndView toUCarDealFlowPage(HttpServletRequest request, HttpServletResponse response) {

		// dictionary：处置接收人类型
		List<KeyValueVO> buyerTypeList = sysDictionaryApiService.getKvList(InterfaceConstants.BUYER_TYPE_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		// 只保留个人和企业
		buyerTypeList = buyerTypeList.stream().filter(k -> "1".equals(k.getKey()) || "2".equals(k.getKey())).collect(Collectors.toList());
		// dictionary：拍卖状态
		List<KeyValueVO> auctionStsList = sysDictionaryApiService.getKvList(AssDealSellConstant.AUCTION_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		// dictionary：到账状态
		List<KeyValueVO> toAccStsList = sysDictionaryApiService.getKvList(AssDealSellConstant.TO_ACC_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		// dictionary：付款方式
		//List<KeyValueVO> payWayCdList = sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_PAY_WAYP_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());


		ModelAndView view = new ModelAndView("ass/assUCarDeal/ucarDealFlowPage");
		Enumeration enu = request.getParameterNames();
		while (enu.hasMoreElements()) {
			String paraName = (String) enu.nextElement();
			view.addObject(paraName, request.getParameter(paraName));
		}

		view.addObject("buyerTypeList", JSON.toJSONString(buyerTypeList));
		view.addObject("auctionStsList", JSON.toJSONString(auctionStsList));
		view.addObject("toAccStsList", JSON.toJSONString(toAccStsList));
		//view.addObject("payWayCdList", JSON.toJSONString(payWayCdList));
		return view;
	}

	/**
	 * 优车处置流程附加页面数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/queryFlowPageDetail.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object queryFlowPageDetail(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		String dealId = request.getParameter("dealId");
		try {
			if (StringUtils.isEmpty(dealId)) {
				throw new BaseException("数据主键不能为空！");
			}
			AssDealSellVO vo = this.assDealSellService.selectById(Long.valueOf(dealId));
			if (null == vo) {
				throw new BaseException("优车处置数据不存在！");
			}
			AssDealCarVO assDealCarVO = assDealCarService.selectById(vo.getDataId());
			if (assDealCarVO == null) {
				throw new BaseException("优车处置数据不存在！");
			}
			JSONObject data = new JSONObject();
			if (assDealCarVO.getPaySchId() != null) {
				// 该支付表是拖车明细中拿到的启用支付表
				List<PrjPrdPaySchMDTO> prjPrdPaySchMDTOS = this.prjPrdPaySchMService.searchTheSamePrdOtherPaySchMList(assDealCarVO.getPaySchId());
				for (PrjPrdPaySchMDTO schMDTO : prjPrdPaySchMDTOS) {
					if (PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS.equals(schMDTO.getPaySchTypCd())) {
						data.put("wsPaySchId", schMDTO.getId().toString());
						data.put("wsPaySchNo", schMDTO.getPaySchNo());
					}
				}
			}
			data.put("dealSell", vo);
			data.put("dealCar", assDealCarVO);
			result.setData(data);
		} catch (BaseException ex) {
			BaseLogUtils.newLogger(CurrentThreadContext.getCurrentUserName() + "查询优车处置流程附加页面数据失败！").setThrowable(ex).setKeys(dealId).error(LogExceptionEnum.COMMON_CODE_0002);
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		} catch (Exception ex) {
			BaseLogUtils.newLogger(CurrentThreadContext.getCurrentUserName() + "查询优车处置流程附加页面数据失败！").setThrowable(ex).setKeys(dealId).error(LogExceptionEnum.COMMON_CODE_0002);
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}
		return result;
	}

	/**
	 * 跳转新增/修改 优车处置付款信息页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toRecAmtPage.do", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView toRecAmtPage(HttpServletRequest request, HttpServletResponse response) {
		String dataId = request.getParameter("dataId");
		String assDealRecAmtId = request.getParameter("assDealRecAmtId");//主键

		ModelAndView view = new ModelAndView("ass/assUCarDeal/ucarDealRecAmtEdit");
		AssDealRecAmtVO recAmtVo = new AssDealRecAmtVO();
		if (StringUtils.isNotEmpty(assDealRecAmtId)) {
			recAmtVo = this.assDealRecAmtService.selectById(Long.valueOf(assDealRecAmtId));
		}
		view.addObject("recAmtVo", recAmtVo);
		view.addObject("dataId", dataId);
		view.addObject("dataTypeCd", "1");

		return view;
	}

	/**
	 * 新增或更新优车处置付款信息
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/addOrUpdateUCarDealPayInfo.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addOrUpdateUCarDealPayInfo(HttpServletRequest request) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		try {
			String recAmtId = request.getParameter("recAmtId");
			String dataId = request.getParameter("dataId");
			String payAmt = request.getParameter("payAmt");
			String receivedAmt = request.getParameter("receivedAmt");
			String useAmt = request.getParameter("useAmt");

			AssDealRecAmtVO vo = getRequestBean(request, AssDealRecAmtVO.class);
			if (StringUtils.isNotEmpty(recAmtId)) {
				vo.setId(Long.parseLong(recAmtId));
			}
			if (StringUtils.isNotEmpty(payAmt)) {
				vo.setPayAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(payAmt)));
			}
			if (StringUtils.isNotEmpty(receivedAmt)) {
				vo.setReceivedAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(receivedAmt)));
			}
			if (StringUtils.isNotEmpty(useAmt)) {
				vo.setUseAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(useAmt)));
			}
			if (StringUtils.isNotEmpty(vo.getPayTmStr())) {
				vo.setPayTm(DateUtils.formatStringToDate(vo.getPayTmStr(), DateUtils.YYYY_MM_DD));
			}
			if (StringUtils.isNotEmpty(vo.getReceivedTmStr())) {
				vo.setReceivedTm(DateUtils.formatStringToDate(vo.getReceivedTmStr(), DateUtils.YYYY_MM_DD));
			}
			if (StringUtils.isNotEmpty(dataId)) {
				vo.setDataId(Long.parseLong(dataId));
			}
			vo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			vo.setMdfTm(new Date());
			if (vo.getId() != null) {
				// 更新
				boolean success = this.assDealRecAmtService.modify(vo);
				if (!success) {
					throw new BaseException("更新优车处置付款信息失败！");
				}
			} else {
				// 新增
				vo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				vo.setCrtTm(new Date());
				vo.setIsDel(BaseConstant.IS_YESNO_NO);
				Long id = this.assDealRecAmtService.add(vo);
				if (id == null) {
					throw new BaseException("新增优车处置付款信息失败！");
				}
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL + "：" + e.getMessage());
			BaseLogUtils.newLogger(CurrentThreadContext.getCurrentUserName() + "新增或更新优车处置付款信息业务异常！").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL + "：" + e.getMessage());
			BaseLogUtils.newLogger(CurrentThreadContext.getCurrentUserName() + "新增或更新优车处置付款信息系统异常！").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		return result;
	}

	/**
	 * 跳转编辑优车处置信息页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toEditDealSellPage.do", method = {RequestMethod.GET})
	public ModelAndView toEditDealSellPage(HttpServletRequest request, HttpServletResponse response) {
		String dealSellId = request.getParameter("dealSellId");
		String type = request.getParameter("type");
		ModelAndView view = new ModelAndView("ass/assUCarDeal/ucarDealSellEdit");

		AssDealSellVO vo = new AssDealSellVO();
		if (StringUtils.isNotEmpty(dealSellId)) {
			vo = this.assDealSellService.selectById(Long.valueOf(dealSellId));
			if (vo == null) {
				throw new BaseException("优车处置信息不存在！");
			}
			if (StringUtils.isEmpty(vo.getPayeeAccNm())) {
				vo.setPayeeAccNm("车正");
			}
		}
		if ("4".equals(type)) {
			if (vo.getDataId() != null) {
				AssDealCarVO assDealCarVO = assDealCarService.selectById(vo.getDataId());
				if (assDealCarVO == null) {
					throw new BaseException("优车处置数据不存在！");
				}
				view.addObject("dealCar", assDealCarVO);
			}
		}
		// 处置接收人类型
		List<KeyValueVO> buyerTypeList = sysDictionaryApiService.getKvList(InterfaceConstants.BUYER_TYPE_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		// 只保留个人和企业
		buyerTypeList = buyerTypeList.stream().filter(k -> "1".equals(k.getKey()) || "2".equals(k.getKey())).collect(Collectors.toList());

		// 拍卖状态
		List<KeyValueVO> auctionStsList = sysDictionaryApiService.getKvList(AssDealSellConstant.AUCTION_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		// 编辑到账状态
		List<KeyValueVO> toAccStsList = sysDictionaryApiService.getKvList(AssDealSellConstant.TO_ACC_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());

		view.addObject("buyerTypeList", JSON.toJSONString(buyerTypeList));
		view.addObject("toAccStsList", JSON.toJSONString(toAccStsList));
		view.addObject("auctionStsList", JSON.toJSONString(auctionStsList));
		view.addObject("dealSell", vo);
		view.addObject("type", type);
		return view;
	}

	/**
	 * 更新优车处置信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/modifyDealSell.do", method = {RequestMethod.POST})
	@ResponseBody
	public Object modifyDealSell(HttpServletRequest request) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		try {
			String assessAmt = request.getParameter("assessAmt");
			String sellAmt = request.getParameter("sellAmt");
			String commissionAmt = request.getParameter("commissionAmt");
			String bfsPayAmt = request.getParameter("bfsPayAmt");
			String bfsPayTmStr = request.getParameter("bfsPayTmStr");
			// 成交时间
			String ycDealTmStr = request.getParameter("ycDealTmStr");
			// 拍卖状态
			String auctionStsCd = request.getParameter("auctionStsCd");
			String dealSellMgrId = request.getParameter("dealSellMgrId");

			AssDealSellVO vo = getRequestBean(request, AssDealSellVO.class);
			if (StringUtils.isEmpty(dealSellMgrId)) {
				vo.setDealSellMgrId(null);
			}
			if (StringUtils.isNotEmpty(assessAmt)) {
				// 车辆评估价
				vo.setAssessAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(assessAmt)));
			}
			if (StringUtils.isNotEmpty(sellAmt)) {
				// 处置金额
				vo.setSellAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(sellAmt)));
			}
			if (StringUtils.isNotEmpty(commissionAmt)) {
				// 佣金
				vo.setCommissionAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(commissionAmt)));
			}
			if (StringUtils.isNotEmpty(bfsPayAmt)) {
				// 实付金额
				vo.setBfsPayAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(bfsPayAmt)));
			}
			if (StringUtils.isNotEmpty(bfsPayTmStr)) {
				// 实付时间
				vo.setBfsPayTm(DateUtils.formatStringToDate(bfsPayTmStr, DateUtils.YYYY_MM_DD));
			}
			boolean modify = assDealSellService.modify(vo);
			if (!modify) {
				throw new BaseException("更新优车处置信息失败！");
			}
			AssDealSellVO newVo = assDealSellService.selectById(vo.getId());
			if (newVo != null) {
				// 更新ass_deal_car表
				AssDealCarVO assDealCarVO = new AssDealCarVO();
				assDealCarVO.setId(newVo.getDataId());
				if (StringUtils.isNotEmpty(ycDealTmStr)) {
					assDealCarVO.setYcDealTm(DateUtils.formatStringToDate(ycDealTmStr, DateUtils.YYYY_MM_DD));
				}
				if (StringUtils.isNotEmpty(auctionStsCd)) {
					assDealCarVO.setAuctionStsCd(auctionStsCd);
				}
				assDealCarVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
				assDealCarVO.setMdfTm(new Date());
				assDealCarService.modify(assDealCarVO);

				// 用户页面回显
				AssDealCarVO dealCar = assDealCarService.selectById(newVo.getDataId());
				newVo.setDealCar(dealCar);
			}
			result.setData(newVo);
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL + "：" + e.getMessage());
			BaseLogUtils.newLogger(CurrentThreadContext.getCurrentUserName() + "修改优车处置信息业务异常！").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL + "：" + e.getMessage());
			BaseLogUtils.newLogger(CurrentThreadContext.getCurrentUserName() + "修改优车处置信息系统异常！").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		return result;
	}

	/**
	 * 跳转费用维护页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toEditCostPage.do", method = {RequestMethod.GET})
	public ModelAndView toEditCostPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");

		ModelAndView view = new ModelAndView("ass/assUCarDeal/ucarDealCostInfoEdit");
		AssDealCarCostVO vo = null;
		if (StringUtils.isNotEmpty(id)) {
			vo = this.assDealCarCostService.selectById(Long.valueOf(id));
			if (vo == null) {
				throw new BaseException("费用信息不存在！");
			}
			if (vo.getSysEmpBankId() != null) {
				SysEmpBankAccVO sysEmpBankAccVO = sysEmpBankAccService.selectById(vo.getSysEmpBankId());
				vo.setEmpBankAcc(sysEmpBankAccVO);
			}
		}
		// 借款类型
		List<KeyValueVO> finLoanTypList = sysDictionaryApiService.getKvList(FinLoanConstant.FIN_LOAN_TYP_DIDC, FinLoanConstant.SYS_CD, FinLoanConstant.ORG_CD);
		// 付款方式
		List<KeyValueVO> finPayTypList = sysDictionaryApiService.getKvList(FinLoanConstant.FIN_PAY_TYP_DIDC, FinLoanConstant.SYS_CD, FinLoanConstant.ORG_CD);

		view.addObject("loanTypList", JSON.toJSONString(finLoanTypList));
		view.addObject("payTypList", JSON.toJSONString(finPayTypList));
		view.addObject("carId", request.getParameter("carId"));
		view.addObject("dealCost", vo);
		return view;
	}

    /**
     * 跳转新增收款方信息页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toAddBankAccPage.do", method = {RequestMethod.GET})
    public ModelAndView toAddBankAccPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("ass/assUCarDeal/ucarDealBankAccAdd");

        List<KeyValueVO> bankDicList = sysDictionaryApiService.getKvList(FinLoanConstant.FIN_BANK_DIC, FinLoanConstant.SYS_CD, FinLoanConstant.ORG_CD);
        List<KeyValueVO> accTypDicList = sysDictionaryApiService.getKvList(FinLoanConstant.FIN_ACC_TYP_DIC, FinLoanConstant.SYS_CD, FinLoanConstant.ORG_CD);

        view.addObject("bankDicList", JSON.toJSONString(bankDicList));
        view.addObject("accTypDicList", JSON.toJSONString(accTypDicList));
        return view;
    }

	/**
	 * 跳转选择优车处置销售经理页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toChooseSellManagerPage.do", method = {RequestMethod.GET})
	public ModelAndView toChooseSellManagerPage(HttpServletRequest request) {
		ModelAndView view = new ModelAndView("ass/assUCarDeal/ucarDealSellManager");
		return view;
	}

	/**
	 * 查询优车处置(销售经理)角色下的用户
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/searchSellManagerList.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object searchSellManagerList(HttpServletRequest request) {
		String usrNm = request.getParameter("userName");
		String rlNm = request.getParameter("realName");

		SysUsrFunAuthRQueryCondition condition = new SysUsrFunAuthRQueryCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		//condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		if (StringUtils.isNotEmpty(usrNm)) {
			condition.setUsrNm(usrNm);
		}
		if (StringUtils.isNotEmpty(rlNm)) {
			condition.setRlNm(rlNm);
		}
		List<AssDealSellDTO> list = null;//assDealSellService.searchSellManagerList(condition);

		return new ListPageVO<>(list, list.size());
	}

	@RequestMapping(value = "/toAddFundPage.do", method = {RequestMethod.GET})
	public ModelAndView toAddFundPage(HttpServletRequest request) {
		//this.prepare(request, mav);
		ModelAndView view = new ModelAndView("/capital/capFund/capFundAddBind");
		String bizTyp = "3";//业务类型 3
		String dealSellId = request.getParameter("dealSellId");

		List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
		view.addObject("fundBelongOrgCdList", JSON.toJSONString(orgList));
		//view.addObject("bizTyp", bizTyp);
		if (StringUtils.isEmpty(dealSellId) || StringUtils.isEmpty(bizTyp)) {
			return view;
		}
		AssDealSellVO sellVO = assDealSellService.selectById(Long.valueOf(dealSellId));
		AssDealCarVO dealCarVO = assDealCarService.selectById(sellVO.getDataId());
//		AssTrailCarDVO carDVO = this.assTrailCarDService.selectById(sellVO.getDetailId());
		Long paySchId = dealCarVO.getPaySchId();

		//查询支付表信息
		PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.selectById(paySchId);
		if (paySchMVO == null) {
			return view;
		}
		//查询项目信息
		PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(paySchMVO.getPrjId());
		if (prjBscInfoVO == null) {
			return view;
		}

		CapFundVO fundVO = new CapFundVO();//来款信息
		fundVO.setRelationPayId(paySchId);//资金管理关联业务ID
		fundVO.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
		fundVO.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人名称
		fundVO.setIdentifyTime(new Date());//认款时间 add时会修改
		//默认财务收款账户、账号
		fundVO.setAcceptName(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_NM);//收款账户
		fundVO.setAcceptCode(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_CD);//收款账号
		fundVO.setPaySchNo(paySchMVO.getPaySchNo());

		//查询客户名称，客户ID,所属事业部
		fundVO.setCstId(paySchMVO.getCstId());
		fundVO.setCstNm(prjBscInfoVO.getCstNm());
		fundVO.setFundBelongOrgCd(prjBscInfoVO.getBuOrgCd());
		fundVO.setComeName(prjBscInfoVO.getCstNm());

		//查询待核销支付表明细列表 支付表号、客户ID、期次、费用类型
		view.addObject("paySchId", paySchMVO.getId());
		view.addObject("cstId", fundVO.getCstId());
		view.addObject("cstNm", prjBscInfoVO.getCstNm());

		//交易日期与实际到账日期默认流程发起时间
		Date flowStartTm = this.capFundService.getFlowStartTime(sellVO.getId(), bizTyp);
		if (null != flowStartTm) {
			fundVO.setAcceptDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
			fundVO.setAcceptActualDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
			fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
			fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
		}
		view.addObject("capFundVO", fundVO);
		view.addObject("stlDtDisableFlag", 0);// 结清时间是否显示，0-否，1-是
		return view;
	}

	/**
	 * request 转换bean
	 * @param request
	 * @param beanClass
	 * @param <T>
	 * @return
	 */
	public static <T> T getRequestBean(HttpServletRequest request, Class<T> beanClass) {
		try {
			/**创建封装数据的bean**/
			T bean = beanClass.newInstance();
			Map map = request.getParameterMap();
			BeanUtils.populate(bean, map);
			return bean;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}

